<?php

namespace App\Enums;

use App\Traits\EnumTrait;

class  OrderStatusEnum
{

    use EnumTrait;

    const CREATED = ['status' => 10, 'text' => '创建完成'];

    const WAIT_PAY = ['status' => 20, 'text' => '待支付'];
    const PAYING = ['status' => 30, 'text' => '支付中'];

    const PAYED = ['status' => 40, 'text' => '支付完成'];

    const WAIT_SEND = ['status' => 50, 'text' => '待发货'];

    const SENDED = ['status' => 60, 'text' => '已发货'];
    const WAIT_RECEIVE = ['status' => 70, 'text' => '待收货'];
    const RECEIVED = ['status' => 80, 'text' => '已收货'];

    const REFUND_ING = ['status' => 90, 'text' => '退款中'];
    const REFUNDED = ['status' => 99, 'text' => '退款完成'];

    const WAIT_EVALUATE = ['status' => 100, 'text' => '待评价'];

    const FINISHED = ['status' => 200, 'text' => '订单完成'];

    const CANCEL = ['status' => 300, 'text' => '订单取消'];


    public static function getEnumByStatus($status): ?array
    {
        foreach (self::getConstants() as $item) {
            if ($status == $item['status']) {
                return $item;
            }
        }
        return null;
    }

    public static function getStatus($enum)
    {
        return $enum['status'];
    }

    public static function getAllByStatus(): array
    {
        return array_column(self::getConstants(),"text",'status');
    }

    public static function getTextByStatus($status)
    {
        foreach (self::getConstants() as $item) {
            if ($status == $item['status']) {
                return $item['text'];
            }
        }
        return null;
    }


    public static function getPayedStatusList(): array
    {
        return [
            self::PAYED['status'],
            self::WAIT_SEND['status'],
            self::SENDED['status'],
            self::WAIT_RECEIVE['status'],
            self::RECEIVED['status'],
            self::WAIT_EVALUATE['status'],
            self::FINISHED['status'],
        ];
    }
}
